var WL_STOP = 1, WL_PAUSE = 2, WL_PLAY = 3, WL_NEXT = 4, WL_PREV = 5, WL_LOOP = 6, WL_SHUF = 7, 
	WL_SAVE = 100, WL_LOAD = 99, WL_PLAYER, WL_PLAYLIST, WL_PREFERENCES, WL_ABOUT;

var g_hWMP = new ActiveXObject("WMPlayer.OCX");
var g_oSettings;

function WL_ShowPlayer(){
	if(!WL_PLAYER){
		WL_PLAYER = WL_CreateWnd("WLMini");
		Interop.Call("user32", "SendMessageW", WL_PLAYER.handle, 0x80, 0, Interop.Call("shell32", "ExtractIconW", 0, "wmploc.dll", 0));
		if(g_oSettings.BACKGROUND_IMAGE)
			WL_PLAYER.ImageElmt_SetImageFile("BGImg", "\\" + g_oSettings.BACKGROUND_IMAGE);
		WL_SetAlpha(WL_PLAYER.handle, g_oSettings.PLAYER_ALPHA);
		WL_PLAYER.Button_SetCheckState("ChkLoop", g_hWMP.settings.getMode("loop"));
		WL_PLAYER.Button_SetCheckState("ChkShuffle", g_hWMP.settings.getMode("shuffle"));
		WL_PLAYER.SendControlMessage("volume", 0x405, 1, g_hWMP.settings.volume);
		WL_PLAYER.RegisterMessageNotification(0x114);
		WL_PLAYER.RegisterMessageNotification(0x233);
		WL_InfoUpdate();
		WL_DataUpdate();
		WL_SetButton();
		}
	Interop.Call("user32", "SwitchToThisWindow", WL_PLAYER.handle, 1);
	}

function WL_ShowPlaylist(){
	if(!WL_PLAYLIST){
		WL_PLAYLIST = WL_CreateWnd("plist");
		WL_SetAlpha(WL_PLAYLIST.handle, g_oSettings.PLAYLIST_ALPHA);
		WL_PLAYLIST.RegisterMessageNotification(0x233);
		WL_LoadPlaylist();
		}
	Interop.Call("user32", "SwitchToThisWindow", WL_PLAYLIST.handle, 1);
	}

function WL_ShowPreferences(){
	if(!WL_PREFERENCES){
		WL_PREFERENCES = WL_CreateWnd("prefs");
		WL_PREFERENCES.SendControlMessage("SldTransPlayer", 0x405, 1, 255-g_oSettings.PLAYER_ALPHA);
		WL_PREFERENCES.SendControlMessage("SldTransPlaylist", 0x405, 1, 255-g_oSettings.PLAYLIST_ALPHA);
		WL_PREFERENCES.Button_SetCheckState("MPSM", g_oSettings.NOW_PLAYING);
		WL_PREFERENCES.Button_SetCheckState("AlbumArt", g_oSettings.ALBUM_ART);
		WL_PREFERENCES.SetControlText("BGImg", g_oSettings.BACKGROUND_IMAGE);
		WL_PREFERENCES.SetControlText("MPSMFormat", g_oSettings.NOW_PLAYING_FORMAT);
		WL_PREFERENCES.SetControlText("LblBGImg", WL_GetLang("PREFS_BACKGROUND"));
		WL_PREFERENCES.SetControlText("LblPlayerSkin", WL_GetLang("PREFS_SKIN"));
		WL_PREFERENCES.SetControlText("LblLangFile", WL_GetLang("PREFS_LANG"));
		WL_PREFERENCES.SetControlText("MPSM", WL_GetLang("PREFS_NOWPLAYING"));
		WL_PREFERENCES.SetControlText("AlbumArt", WL_GetLang("PREFS_ALBUMART"));
		WL_PREFERENCES.SetControlText("LblTransPlayer", WL_GetLang("PREFS_PLAYERALPHA"));
		WL_PREFERENCES.SetControlText("LblTransPlaylist", WL_GetLang("PREFS_PLAYLISTALPHA"));
		WL_PREFERENCES.SetControlText("BtnAccept", WL_GetLang("PREFS_ACCEPT"));
		WL_PREFERENCES.SetControlText("BtnCancel", WL_GetLang("PREFS_CANCEL"));
		
		var aSkins = WL_GetFiles(MsgPlus.ScriptFilesPath + "\\skins"), aLangs = WL_GetFiles(MsgPlus.ScriptFilesPath + "\\langs");
		var iSkinCount = aSkins.length, iLangCount = aLangs.length;
		
		for(i in aSkins)
			WL_PREFERENCES.Combo_AddItem("PlayerSkin", aSkins[i].Name);
		for(i in aLangs)
			WL_PREFERENCES.Combo_AddItem("LanguageFile", aLangs[i].Name);
		
		for(i=0;WL_PREFERENCES.GetControlText("PlayerSkin") != g_oSettings.PLAYER_SKIN && i<iSkinCount;i++)
			WL_PREFERENCES.Combo_SetCurSel("PlayerSkin", i);
		for(i=0;WL_PREFERENCES.GetControlText("LanguageFile") != g_oSettings.LANGUAGE && i<iLangCount;i++)
			WL_PREFERENCES.Combo_SetCurSel("LanguageFile", i);
		}
	Interop.Call("user32", "SwitchToThisWindow", WL_PREFERENCES.handle, 1);
	}

function WL_ShowAbout(){
	if(!WL_ABOUT){
		WL_ABOUT = WL_CreateWnd("AboutBox");
		WL_ABOUT.SetControlText("lblSpecialThanks", WL_GetLang("ABOUT_SPECIALTHANKS"));
		WL_ABOUT.SetControlText("lblMoreInfo", WL_GetLang("ABOUT_MOREINFO"));
		WL_ABOUT.SetControlText("BtnCancel", WL_GetLang("ABOUT_CLOSE"));
		}
	Interop.Call("user32", "SwitchToThisWindow", WL_ABOUT.handle, 1);
	}

function WL_Controls(type){
	switch(type){
		case WL_PLAY:eval("g_hWMP.controls.play" + (arguments.length==2&&arguments[1]>-1?"Item(g_hWMP.currentPlaylist.item(arguments[1]))":"()"));break;
		case WL_PAUSE:g_hWMP.controls.pause();break;
		case WL_STOP:g_hWMP.controls.stop();break;
		case WL_NEXT:g_hWMP.controls.next();break;
		case WL_PREV:g_hWMP.controls.previous();break;
		case WL_LOOP:case WL_SHUF:
		var szType = type==WL_LOOP?"loop":"shuffle";
		g_hWMP.settings.setMode(szType, g_oSettings[szType] = !g_hWMP.settings.getMode(szType));
		}
	}